import React, { useContext, useEffect } from "react";

import { context } from "./components/AppProvider";
import { Routes, Route } from "react-router";
import Layouts from "./view/Layouts.jsx";

export default function App() {
  const { routes } = useContext(context);
  // 退出页面去除本地的登录信息
  useEffect(() => {
    return () => {
      localStorage.removeItem("globalState");
      sessionStorage.removeItem("globalState");
    };
  }, []);
  return (
    <Layouts>
      {/* 动态渲染登录的路由 */}
      <Routes>
        {routes &&
          routes.map(
            (item) =>
              item.element && (
                <Route
                  key={item.key}
                  path={item.key.replace("/layouts", "")}
                  element={item.element}
                />
              )
          )}
      </Routes>
    </Layouts>
  );
}
